package com.ai.config.security.handler;

import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SecurityFilter  {
//    extends UsernamePasswordAuthenticationFilter
//    private static boolean postOnly = true;
//
//    @Override
//    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
//        if (this.postOnly && !request.getMethod().equals("POST")) {
//            throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
//        }
//        try {
//            System.out.println("----> 进入过滤器 ");
//            String username = request.getParameter(getUsernameParameter());
//            String password = request.getParameter(getPasswordParameter());
//            System.out.println(username + " " + password);
//            UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
//            setDetails(request, token);
//            return this.getAuthenticationManager().authenticate(token);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return super.attemptAuthentication(request, response);
//    }
}